﻿using CommHelper; 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;

namespace NX5WinServies
{
    public partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
        }

        protected override void OnStop()
        {
        }  

        private async void FiveMinuteTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            FiveMinuteTimer.Enabled = false;
            try
            {
                Sentence sts = new Sentence();
                await sts.StartSplit();
                await sts.Audio();
                await sts.Media();

                Words words = new Words();
                words.Syllable();
                await words.Method();
                await words.MP3();
                words.SDEMethods();
            }
            catch(Exception ex)
            {
                Log.Write(ex.ToString());
            }
            FiveMinuteTimer.Enabled = true;
        }

        private void MinuteTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            MinuteTimer.Enabled = false;
            try
            {
                Lesson.ChangeLessonStatus();
            }
            catch (Exception ex)
            {
                Log.Write(ex.ToString());
            }
            MinuteTimer.Enabled = true;
        }

        private void MinuteTimer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            MinuteTimer1.Enabled = false;

            try
            {
                Lesson.SendMsg();
            }
            catch (Exception ex)
            {
                Log.Write(ex.ToString());
            }
            MinuteTimer1.Enabled = true;
        }

        private void Day00_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            Day00.Enabled = false;

            if(DateTime.Now.Hour == 0)
            {
                //检查账号过期
                EverydayCheck.CheckAccountPreoid();
                //检查课程评价
                EverydayCheck.CheckLessonEvl();
                //检查已过期的预约
                EverydayCheck.CheckOuttimeLesson();
                //每月一号自动结算
                EverydayCheck.AutoSettle();
            }

            Day00.Enabled = true;
        }
    }
}
